package gui.cliente;

import java.awt.Dimension;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;

import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.SpinnerListModel;

import common.AutoCompleteComboBox;
import common.KeyFilterJListener;
import db.DBConnection;
import db.DBInteraction;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class TestFiltroTempoReale extends javax.swing.JPanel {
	private JTextField jTextField1;
	private JList jList1;
	private JComboBox jComboBox1;
	private JFormattedTextField jFormattedTextField1;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new TestFiltroTempoReale());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public TestFiltroTempoReale() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			this.setPreferredSize(new java.awt.Dimension(398, 300));
			this.addKeyListener(new KeyAdapter() {
				public void keyPressed(KeyEvent evt) {
					System.out.println("this.keyPressed, event="+evt);
					//TODO add your code for this.keyPressed
				}
			});
			{
				jTextField1 = new JTextField();
				this.add(jTextField1);
				jTextField1.setText("jTextField1");
			}
			{
				ListModel jList1Model = 
						new DefaultComboBoxModel(
								new String[] { "Item One", "Item Two" });
				jList1 = new JList();
				this.add(jList1);
				jList1.setModel(jList1Model);
			}
			{
				jFormattedTextField1 = new JFormattedTextField();
				this.add(jFormattedTextField1);
				jFormattedTextField1.setPreferredSize(new java.awt.Dimension(99, 23));
				jFormattedTextField1.addKeyListener(new KeyFilterJListener(jFormattedTextField1));
			}
			{
				jComboBox1 = new JComboBox(this.loadCities());
				this.add(jComboBox1);

				jComboBox1.setEditable(true);
				new S19PrototypeValue(jComboBox1);
			}
	        
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	private String[] loadCities() 
	{
		DBConnection dbCon;
		try {
			dbCon = new DBConnection();
			String query = "SELECT COUNT(*) FROM Comune;";
			ResultSet res = DBInteraction.executeQuery(dbCon, query);
			res.next();
			String[] comuni = new String[res.getInt(1)];
			query = "SELECT Nome FROM Comune;";
			res = DBInteraction.executeQuery(dbCon, query);
			int i=0;
			while(res.next()) 
			{
				comuni[i++] = res.getString(1);
			}
			return comuni;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}

}
